package com.tnl.app.dao;

import java.util.Date;

import org.springframework.stereotype.Repository;

import com.tnl.app.entity.SchJobPerson;
import com.tnl.app.entity.SchPerson;
import com.tnl.base.BaseDAO;

@Repository
public class SchPersonDAO {

//	private final static String SQL_UPDATE = "update sch_person set name=?,sex=?,mobile=?,"
//			+ "idCard=?,liveIn=?,school=?,specialty=?,highestDegree=?,graduateDate=?,returnee=?,"
//			+ "exceptDomain=?,exceptCompany1=?,exceptCompany2=?,exceptCompany3=?,exceptCity=?,"
//			+ "updateTime=now() where id = ?";
//	public void update(SchPerson schPerson) {
//		// TODO Auto-generated method stub
//		BaseDAO.execute(SQL_UPDATE, schPerson.getName(),schPerson.getSex(),schPerson.getMobile(),
//				schPerson.getIdCard(),schPerson.getLiveIn(),schPerson.getSchool(),
//				schPerson.getSpecialty(),schPerson.getHighestDegree(),schPerson.getGraduateDate(),
//				schPerson.getReturnee(),schPerson.getExceptDomain(),schPerson.getExceptCompany1(),
//				schPerson.getExceptCompany2(),schPerson.getExceptCompany3(),schPerson.getExceptCity(),
//				schPerson.getId());
//	}

	private final static String SQL_GETBYID = "select * from sch_person where id =?";
	public SchPerson getById(String id) {
		// TODO Auto-generated method stub
		return BaseDAO.queryForObject(SchPerson.class, SQL_GETBYID, id);
	}

//	private final static String SQL_INSERT = "insert sch_person (id,name,sex,mobile,idCard,"
//			+ "liveIn,school,specialty,highestDegree,graduateDate,returnee,exceptDomain,exceptCompany1,"
//			+ "exceptCompany2,exceptCompany3,exceptCity,createTime,updateTime) values (?,?,?,?,?,?,?,?,"
//			+ "?,?,?,?,?,?,?,?,?,now(),now())";
//	public void insert(SchPerson schPerson) {
//		// TODO Auto-generated method stub
//		BaseDAO.execute(SQL_INSERT, schPerson.getId(),schPerson.getUnionid(),schPerson.getName(),schPerson.getSex(),
//				schPerson.getMobile(),schPerson.getIdCard(),schPerson.getLiveIn(),schPerson.getSchool(),
//				schPerson.getSpecialty(),schPerson.getHighestDegree(),schPerson.getGraduateDate(),schPerson.getReturnee(),
//				schPerson.getExceptDomain(),schPerson.getExceptCompany1(),schPerson.getExceptCompany2(),
//				schPerson.getExceptCompany3(),schPerson.getExceptCity());
//	}
	
	private final static String SQL_GETBYUNIONID = "select * from sch_person where unionid =?";
	public SchPerson getByUnionid(String unionid) {
		// TODO Auto-generated method stub
		return BaseDAO.queryForObject(SchPerson.class, SQL_GETBYUNIONID, unionid);
	}
	private final static String SQL_HASSENDEMAIL = "select * from sch_job_person where unionid = ? and jobId = ?";
	public SchJobPerson hasSendEmail(String unionid, String jobId) {
		// TODO Auto-generated method stub
		return BaseDAO.queryForObject(SchJobPerson.class, SQL_HASSENDEMAIL, unionid, jobId);
	}
	private final static String SQL_INSERTRECORD = "insert into sch_job_person (unionid,jobId,createTime) values (?,?,?)";
	public int addSendRecord(String unionid, String jobId) {
		// TODO Auto-generated method stub
		return BaseDAO.execute(SQL_INSERTRECORD, unionid,jobId,new Date());
	}
	
	private final static String SQL_ADDBASE = "insert into sch_person (id,unionid,sex,name,mobile,idCard,"
			+ "liveIn,school,specialty,highestDegree,graduateDate,returnee,createTime,flag) values("
			+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
	public String addBase(SchPerson schPerson) {
		// TODO Auto-generated method stub
		 BaseDAO.execute(SQL_ADDBASE, schPerson.getId(),schPerson.getUnionid(),
				schPerson.getSex(),schPerson.getName(),schPerson.getMobile(),
				schPerson.getIdCard(),schPerson.getLiveIn(),schPerson.getSchool(),schPerson.getSpecialty(),
				schPerson.getHighestDegree(),schPerson.getGraduateDate(),schPerson.getReturnee(),new Date(),schPerson.getFlag());
		 return schPerson.getId();
	}
	private final static String UPDATE_BASE = "update sch_person set name=?,mobile=?,"
			+ "idCard=?,liveIn=?,school=?,specialty=?,highestDegree=?,graduateDate=?,returnee=?,"
			+ "updateTime=? where id = ?";
	public void updateBase(SchPerson schPerson) {
		// TODO Auto-generated method stub
		BaseDAO.execute(UPDATE_BASE, schPerson.getName(),schPerson.getMobile(),
				schPerson.getIdCard(),schPerson.getLiveIn(),schPerson.getSchool(),
				schPerson.getSpecialty(),schPerson.getHighestDegree(),schPerson.getGraduateDate(),
				schPerson.getReturnee(),new Date(),schPerson.getId());
	}
	private final static String UPDATE_EXCEPT = "update sch_person set exceptCity1=?,exceptCity2=?,"
			+ "exceptCity3=?,exceptCityName1=?,exceptCityName2=?,exceptCityName3=?,exceptDomain=?,exceptCompany1=?,"
			+ "exceptCompany2=?,exceptCompany3=?,exceptCompanyName1=?,exceptCompanyName2=?,"
			+ "exceptCompanyName3=? where id = ?";
	public void updateExcept(SchPerson schPerson) {
		// TODO Auto-generated method stub
		BaseDAO.execute(UPDATE_EXCEPT, schPerson.getExceptCity1(),schPerson.getExceptCity2(),schPerson.getExceptCity3(),
				schPerson.getExceptCityName1(),schPerson.getExceptCityName2(),schPerson.getExceptCityName3(),schPerson.getExceptDomain(),
				schPerson.getExceptCompany1(),schPerson.getExceptCompany2(),schPerson.getExceptCompany3(),
				schPerson.getExceptCompanyName1(),schPerson.getExceptCompanyName2(),schPerson.getExceptCompanyName3(),
				schPerson.getId());
	}
	

}
